﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.PlanningManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.PlanningManagement.ProductionOrderVMs
{
    public partial class ProductionOrderListVM : BasePagedListVM<ProductionOrder_View, ProductionOrderSearcher>
    {
        
        protected override IEnumerable<IGridColumn<ProductionOrder_View>> InitGridHeader()
        {
            return new List<GridColumn<ProductionOrder_View>>{
                
                this.MakeGridHeader(x => x.ProductionOrder_Plan).SetTitle(@Localizer["Page.关联计划"].Value),
                this.MakeGridHeader(x => x.ProductionOrder_ProductId).SetTitle(@Localizer["Page.产品"].Value),
                this.MakeGridHeader(x => x.ProductionOrder_ProductCode).SetTitle(@Localizer["Page.产品名称"].Value),
                this.MakeGridHeader(x => x.ProductionOrder_ProductName).SetTitle(@Localizer["Page.产品名称"].Value),
                this.MakeGridHeader(x => x.ProductionOrder_Wo).SetTitle(@Localizer["Page.工单号"].Value),
                this.MakeGridHeader(x => x.ProductionOrder_PlanQty).SetTitle(@Localizer["Page.计划数量"].Value),
                this.MakeGridHeader(x => x.ProductionOrder_OnlineQty).SetTitle(@Localizer["Page.上线数量"].Value),
                this.MakeGridHeader(x => x.ProductionOrder_CompletedQty).SetTitle(@Localizer["Page.完工数量"].Value),
                this.MakeGridHeader(x => x.ProductionOrder_QualifiedQty).SetTitle(@Localizer["Page.合格数量"].Value),
                this.MakeGridHeader(x => x.ProductionOrder_UnqualifiedQty).SetTitle(@Localizer["Page.不合格数量"].Value),
                this.MakeGridHeader(x => x.ProductionOrder_ScrapQty).SetTitle(@Localizer["Page.报废数量"].Value),
                this.MakeGridHeader(x => x.ProductionOrder_PlanStartTime).SetTitle(@Localizer["Page.计划开始时间"].Value),
                this.MakeGridHeader(x => x.ProductionOrder_PlanEndTime).SetTitle(@Localizer["Page.计划结束时间"].Value),
                this.MakeGridHeader(x => x.ProductionOrder_ActualStartTime).SetTitle(@Localizer["Page.实际开始时间"].Value),
                this.MakeGridHeader(x => x.ProductionOrder_ActualEndTime).SetTitle(@Localizer["Page.实际完工时间"].Value),
                this.MakeGridHeader(x => x.ProductionOrder_OrderStatus).SetTitle(@Localizer["Page.订单状态"].Value),
                this.MakeGridHeader(x => x.ProductionOrder_OrderSource).SetTitle(@Localizer["Page.订单来源"].Value),
                this.MakeGridHeader(x => x.ProductionOrder_Sort).SetTitle(@Localizer["Page.排序"].Value),
                this.MakeGridHeader(x => x.ProductionOrder_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.ProductionOrder_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.ProductionOrder_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.ProductionOrder_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<ProductionOrder_View> GetSearchQuery()
        {
            var query = DC.Set<ProductionOrder>()
                
                .CheckEqual(Searcher.PlanId, x=>x.PlanId)
                .CheckEqual(Searcher.ProductId, x=>x.ProductId)
                .CheckContain(Searcher.ProductCode, x=>x.ProductCode)
                .CheckContain(Searcher.ProductName, x=>x.ProductName)
                .CheckContain(Searcher.Wo, x=>x.Wo)
                .CheckEqual(Searcher.PlanQty, x=>x.PlanQty)
                .CheckEqual(Searcher.OnlineQty, x=>x.OnlineQty)
                .CheckEqual(Searcher.CompletedQty, x=>x.CompletedQty)
                .CheckEqual(Searcher.QualifiedQty, x=>x.QualifiedQty)
                .CheckEqual(Searcher.UnqualifiedQty, x=>x.UnqualifiedQty)
                .CheckEqual(Searcher.ScrapQty, x=>x.ScrapQty)
                .CheckBetween(Searcher.PlanStartTime?.GetStartTime(), Searcher.PlanStartTime?.GetEndTime(), x => x.PlanStartTime, includeMax: false)
                .CheckBetween(Searcher.PlanEndTime?.GetStartTime(), Searcher.PlanEndTime?.GetEndTime(), x => x.PlanEndTime, includeMax: false)
                .CheckBetween(Searcher.ActualStartTime?.GetStartTime(), Searcher.ActualStartTime?.GetEndTime(), x => x.ActualStartTime, includeMax: false)
                .CheckBetween(Searcher.ActualEndTime?.GetStartTime(), Searcher.ActualEndTime?.GetEndTime(), x => x.ActualEndTime, includeMax: false)
                .CheckEqual(Searcher.OrderStatus, x=>x.OrderStatus)
                .CheckEqual(Searcher.OrderSource, x=>x.OrderSource)
                .CheckEqual(Searcher.Sort, x=>x.Sort)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new ProductionOrder_View
                {
				    ID = x.ID,                    
                    ProductionOrder_Plan = x.Plan.Wo,
                    ProductionOrder_ProductId = x.ProductId,
                    ProductionOrder_ProductCode = x.Product.Code,
                    ProductionOrder_ProductName = x.Product.Name,
                    ProductionOrder_Wo = x.Wo,
                    ProductionOrder_PlanQty = x.PlanQty,
                    ProductionOrder_OnlineQty = x.OnlineQty,
                    ProductionOrder_CompletedQty = x.CompletedQty,
                    ProductionOrder_QualifiedQty = x.QualifiedQty,
                    ProductionOrder_UnqualifiedQty = x.UnqualifiedQty,
                    ProductionOrder_ScrapQty = x.ScrapQty,
                    ProductionOrder_PlanStartTime = x.PlanStartTime,
                    ProductionOrder_PlanEndTime = x.PlanEndTime,
                    ProductionOrder_ActualStartTime = x.ActualStartTime,
                    ProductionOrder_ActualEndTime = x.ActualEndTime,
                    ProductionOrder_OrderStatus = x.OrderStatus,
                    ProductionOrder_OrderSource = x.OrderSource,
                    ProductionOrder_Sort = x.Sort,
                    ProductionOrder_CreateTime = x.CreateTime,
                    ProductionOrder_UpdateTime = x.UpdateTime,
                    ProductionOrder_CreateBy = x.CreateBy,
                    ProductionOrder_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class ProductionOrder_View: ProductionOrder
    {
        
        public string ProductionOrder_Plan { get; set; }
        public long? ProductionOrder_ProductId { get; set; }
        public string ProductionOrder_ProductCode { get; set; }
        public string ProductionOrder_ProductName { get; set; }
        public string ProductionOrder_Wo { get; set; }
        public decimal? ProductionOrder_PlanQty { get; set; }
        public decimal? ProductionOrder_OnlineQty { get; set; }
        public decimal? ProductionOrder_CompletedQty { get; set; }
        public decimal? ProductionOrder_QualifiedQty { get; set; }
        public decimal? ProductionOrder_UnqualifiedQty { get; set; }
        public decimal? ProductionOrder_ScrapQty { get; set; }
        public DateTime? ProductionOrder_PlanStartTime { get; set; }
        public DateTime? ProductionOrder_PlanEndTime { get; set; }
        public DateTime? ProductionOrder_ActualStartTime { get; set; }
        public DateTime? ProductionOrder_ActualEndTime { get; set; }
        public WoStatusEnum? ProductionOrder_OrderStatus { get; set; }
        public WoSourceEnum? ProductionOrder_OrderSource { get; set; }
        public int? ProductionOrder_Sort { get; set; }
        public DateTime? ProductionOrder_CreateTime { get; set; }
        public DateTime? ProductionOrder_UpdateTime { get; set; }
        public string ProductionOrder_CreateBy { get; set; }
        public string ProductionOrder_UpdateBy { get; set; }

    }

}